<?php
include_once ('class/autoload.php'); // pour inclure nos classes
include_once ('class/config.inc.php');

$site = new page_securisee ( 'Detail', "Detail de l'appel", "" );
if (! isset ( $_POST ['commentaire'] )) {
	$requete = 'SELECT * FROM appels as a
			INNER JOIN praticiens AS p ON a.idclient = p.id
			INNER JOIN problematique AS pr ON a.idproblematique = pr.id
			INNER JOIN utilisateurs AS u ON a.idtech = u.id
			INNER JOIN priorite AS prio ON a.idpriorite = prio.id
			INNER JOIN cloturer AS c ON c.id = a.idcloturer
			WHERE idAppels="' . $_POST ['modifier'] . '";';
	$result = $connexion->query ( $requete );
	$result->setFetchMode ( PDO::FETCH_OBJ );
	if ($result->rowCount () < 1) {
		$corps .= '<p>Aucun ticket répertoriés.';
	} else {
		while ( $OneRow = $result->fetch () ) {
			$corps = '
			<form action="DetailsAppels.php" method="POST">
			<input type="hidden" name="id" value="' . $_POST ['modifier'] . '">
						<p>Nom du client :</p>
				<input type="text" disabled name="clients2" value="' . $OneRow->nom . ' ' . $OneRow->prenom . '">
			<table>
			
			
				<tr><td>
						<p>Problématique :</p>
				<input type="text" disabled name="nature" value="' . $OneRow->nature . '">
						</td><td>
				<p>Date de l\'appel :</p>
						
				<input type="text" disabled name="date" value="' . $OneRow->dateDebut . '">
						</td>
						<td>
						<p>Technicien assigné :</p>
						<select name="techAssigne" value="">
						';
			$requete2 = 'SELECT * FROM utilisateurs';
			$result2 = $connexion->query ( $requete2 );
			$result2->setFetchMode ( PDO::FETCH_OBJ );
			
			while ( $OneRow2 = $result2->fetch () ) {
				if ($OneRow2->id == $OneRow->idtech) {
					$corps .= '<option selected value=' . $OneRow2->id . '>' . $OneRow2->identifiant . '</option>';
				} else {
					$corps .= '<option value=' . $OneRow2->id . '>' . $OneRow2->identifiant . '</option>';
				}
			}
			;
			$corps .= '</select>
						</td>
						</tr><tr><td>
						<p>Etat du dossier :</p>
				<select name ="cloturer" id="Cloture" onchange="disablePriorite()" >';
			$requete2 = 'SELECT * FROM cloturer WHERE id !=0';
			$result2 = $connexion->query ( $requete2 );
			$result2->setFetchMode ( PDO::FETCH_OBJ );
			
			while ( $OneRow2 = $result2->fetch () ) {
				if ($OneRow2->reponse == $OneRow->reponse) {
					$corps .= '<option selected value=' . $OneRow2->id . '>' . $OneRow2->reponse . '</option>';
				} else {
					$corps .= '<option value=' . $OneRow2->id . '>' . $OneRow2->reponse . '</option>';
				}
			}
			;
			$corps .= '</select>
						</td><td>
				<p>Priorité :</p>
						<select name ="priorite" id="prioritedisable">';
			$requete3 = 'SELECT * FROM priorite WHERE id != 4';
			$result3 = $connexion->query ( $requete3 );
			$result3->setFetchMode ( PDO::FETCH_OBJ );
			while ( $OneRow3 = $result3->fetch () ) {
				if ($OneRow3->libelle == $OneRow->libelle) {
					$corps .= '<option selected value=' . $OneRow3->id . '>' . $OneRow3->libelle . '</option>';
				} else {
					$corps .= '<option value=' . $OneRow3->id . '>' . $OneRow3->libelle . '</option>';
				}
			}
			
			$corps .= '</select>
				
						</td>
					<td>
					<p>Durée :</p>
					<input type="text" name="date" value="' . $OneRow->duree . '">
					
					</td></tr>
				</table>
				<p>Commentaire :</p>
				<textarea type="textbox" name="commentaire" class="form-control" rows="3" style="margin: 0px 0px 10px; width: 890px; height: 160px; max-width: 890px; ">' . $OneRow->commentaires . '</textarea>
					<br>
						
				<input type="submit" class="btn btn-large btn-primary" value="Modifier l\'appel">
						<a href="AccueilConnecter.php"> <input type="button" class="btn btn-large btn-primary" value="Accueil">  </a></td>
						</form>';
		}
	}
} else {
	if ($_POST ['cloturer'] == 1) {
		$requete = 'UPDATE appels SET commentaires ="' . addslashes ( $_POST ['commentaire'] ) . '", duree = "' . $_POST ['date'] . '", idtech = "' . $_POST ['techAssigne'] . '", idpriorite=4, idcloturer=1 WHERE idappels="' . $_POST ['id'] . '";';
	} else {
		$requete = 'UPDATE appels SET commentaires ="' . addslashes ( $_POST ['commentaire'] ) . '", duree = "' . $_POST ['date'] . '", idtech = "' . $_POST ['techAssigne'] . '", idpriorite="' . $_POST ['priorite'] . '", idcloturer="' . $_POST ['cloturer'] . '" WHERE idappels="' . $_POST ['id'] . '";';
	}
	$result = $connexion->query ( $requete );
	$corps = '<a href="ConsultationTicket.php?name=nonclotures"> <input type="button" class="btn btn-large btn-primary" value="Modifier un autre ticket">  </a><a href="AccueilConnecter.php"> <input type="button"  class="btn btn-large btn-primary" value="Accueil">  </a>';
}
$site->corps = $corps;
$site->affiche ();
?>